package com.example.jdai.jdai.ui.wig;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.jdai.jdai.R;

import butterknife.BindColor;
import butterknife.BindDrawable;
import butterknife.BindString;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hellopyj on 2017/1/25.
 */

public class ShengheTip extends LinearLayout {
    @BindView(R.id.iv_tip1)
    ImageView ivTip1;
    @BindView(R.id.tv_tip1)
    TextView tvTip1;
    @BindView(R.id.tv_data1)
    TextView tvData1;
    @BindView(R.id.iv_tip2)
    ImageView ivTip2;
    @BindView(R.id.tv_tip2)
    TextView tvTip2;
    @BindView(R.id.tv_data2)
    TextView tvData2;
    @BindView(R.id.iv_tip3)
    ImageView ivTip3;
    @BindView(R.id.tv_tip3)
    TextView tvTip3;
    @BindView(R.id.tv_data3)
    TextView tvData3;
    @BindDrawable(R.drawable.shenghe_tip_fail)
    Drawable fail;
    @BindDrawable(R.drawable.shenghe_tip_no)
    Drawable no;
    @BindDrawable(R.drawable.shenghe_tip_success)
    Drawable success;
    @BindString(R.string.sh_tj)
    String sh_tj;
    @BindString(R.string.sh_about)
    String sh_about;
    @BindString(R.string.sh_ing)
    String sh_ing;
    @BindString(R.string.sh_jg)
    String sh_jg;
    @BindString(R.string.sh_sb)
    String sh_sb;
    @BindString(R.string.sh_success)
    String sh_success;
    @BindString(R.string.sh_ok)
    String sh_ok;
    @BindColor(R.color.sh_red)
    int sh_red;
    @BindColor(R.color.gray_text)
    int gray;
    @BindColor(R.color.sh_green)
    int green;
    @BindView(R.id.bt_refill)
    Button btRefill;
    @BindView(R.id.tv_data4)
    TextView tvData4;
    @BindView(R.id.tv_reason)
    TextView tvReason;

    public ShengheTip(Context context) {
        super(context);
        init(context, null);
    }

    public ShengheTip(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public ShengheTip(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    public ShengheTip(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs);
    }

    void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(R.layout.shenghe_tip, this);
        ButterKnife.bind(this);
    }

    public void setTip(String index, String createTime, String verifyTime, String n,String reason) {
        if ("1".equals(index)) {
            ivTip1.setImageDrawable(success);
            ivTip2.setImageDrawable(success);
            ivTip3.setImageDrawable(success);
            tvTip1.setText(sh_tj);
            tvTip2.setText(sh_success);
            tvTip3.setText(sh_ok);
            btRefill.setVisibility(GONE);
            tvTip3.setTextColor(green);
            if (!TextUtils.isEmpty(createTime)) {
                tvData1.setText(createTime);
            }
            if (!TextUtils.isEmpty(verifyTime)) {
                tvData2.setText(verifyTime);
                tvData3.setText(verifyTime);
            }
            if (!TextUtils.isEmpty(n)) {
                tvData4.setText("您已获得" + n + "元额度，\n工作人员将会联系您，\n请保持手机通话畅通。");
                tvData4.setVisibility(VISIBLE);
            }
        }
        if ("2".equals(index)) {
            ivTip1.setImageDrawable(success);
            ivTip2.setImageDrawable(success);
            ivTip3.setImageDrawable(fail);
            tvTip1.setText(sh_tj);
            tvTip2.setText(sh_success);
            tvTip3.setText(sh_sb);
            tvTip3.setTextColor(sh_red);
            tvData3.setVisibility(INVISIBLE);
            btRefill.setVisibility(VISIBLE);
            if (!TextUtils.isEmpty(createTime)) {
                tvData1.setText(createTime);
            }
            if (!TextUtils.isEmpty(verifyTime)) {
                tvData2.setText(verifyTime);
                //tvData3.setText(verifyTime);
            }

            if(!TextUtils.isEmpty(reason)){
                tvReason.setVisibility(VISIBLE);
                tvReason.setText(reason);

            }
            tvData4.setVisibility(INVISIBLE);


        }
        if ("3".equals(index)) {
            ivTip1.setImageDrawable(success);
            ivTip2.setImageDrawable(success);
            ivTip3.setImageDrawable(no);
            tvTip1.setText(sh_tj);
            tvTip2.setText(sh_ing);
            tvData2.setText("您的申请正在审核中,\n预计需要1~3个工作日,\n如遇节假日需要顺延哦。");
            tvTip3.setText(sh_jg);
            tvTip3.setTextColor(gray);
            tvData3.setVisibility(INVISIBLE);
            btRefill.setVisibility(GONE);
            if (!TextUtils.isEmpty(createTime)) {
                tvData1.setText(createTime);
            }
            tvData4.setVisibility(INVISIBLE);
        }
        if("4".equals(index)){
            ivTip1.setImageDrawable(success);
            ivTip2.setImageDrawable(success);
            ivTip3.setImageDrawable(fail);
            tvTip1.setText(sh_tj);
            tvTip2.setText(sh_success);
            tvTip3.setText(sh_sb);
            tvTip3.setTextColor(sh_red);
            tvData3.setVisibility(INVISIBLE);
            btRefill.setVisibility(GONE);
            if (!TextUtils.isEmpty(createTime)) {
                tvData1.setText(createTime);
            }
            if (!TextUtils.isEmpty(verifyTime)) {
                tvData2.setText(verifyTime);
                //tvData3.setText(verifyTime);
            }
            if(!TextUtils.isEmpty(reason)){
                tvReason.setVisibility(VISIBLE);
                tvReason.setText(reason);

            }
            tvData4.setVisibility(INVISIBLE);
        }

    }

    public void setReFill(OnClickListener oc) {
        btRefill.setOnClickListener(oc);
    }
}
